/**
 * Created by zhuhuijun on 2017-9-15 14:38:58
 */
app.controller('OrderCtrl', OrderCtrl);
OrderCtrl.$inject = ['$scope', 'ngTableService', 'customerService', 'productService', 'toaster', 'layerService'];
function OrderCtrl($scope, ngTableService, customerService, productService, toaster, layerService) {
    var vm = this;
    //all function here
    //-----------------
    vm.init = init;
    vm.openCustomer = openCustomer;
    vm.openProduct = openProduct;
    vm.order = {};
    vm.checkboxes = {
        checked: false,
        items: {}
    };
    //all function call here
    //-----------------------
    function init() {
        openCustomer();
    }

    function openCustomer() {
        customerService.findAll().then(function (response) {
            vm.customerList = response.data;
        });
    }

    function openProduct() {
        productService.findAll().then(function (response) {
            vm.productList = response.data;
            vm.productTableParam = ngTableService.init(vm.productList);
            ngTableService.watchCheckBox(vm.checkboxes, vm.productList);

            layerService.popupWindow("批量添加商品", $("#productList"), {}, function (layerno) {
                vm.hasChoiceDataList = ngTableService.getChoiceData(vm.productList,vm.checkboxes.items);
                vm.checkboxes={};
                // vm.tableParam = ngTableService.init(vm.hasChoiceDataList);
                vm.tableParam = ngTableService.addRow(vm.tableParam, vm.hasChoiceDataList);
            });

        });
    }

}
